//
//  CFProgressHUD.h
//  CFProgressHUD
//
//  Created by 千域互联 on 2018/3/16.
//  Copyright © 2018年 千域互联. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "CFProgressConst.h"
#import "CFProgressHUDShadow.h"

#import "CFProgressHUDAnimation.h"
#import "CFProgressHUDFadeAnimation.h"
#import "CFProgressHUDFadeZoomAnimation.h"

#import "CFProgressHUDIndicatorView.h"

#import "CFProgressHUDSuccessIndicatorView.h"
#import "CFProgressHUDErrorIndicatorView.h"

#import "CFProgressHUDRingIndicatorView.h"
#import "CFProgressHUDPieIndicatorView.h"

#import "CFProgressHUDIndeterminateIndicatorView.h"

#import "UIImage+CFProgressHUD.h"

@protocol CFProgressHUDDelegate;

@interface CFProgressHUD : UIView

- (instancetype __nonnull)initWithStyle:(CFProgressHUDStyle)style;
+ (instancetype __nonnull)progressHUDWithStyle:(CFProgressHUDStyle)style;

/** HUD显示样式 默认 CFProgressHUDStyleDark */
@property (nonatomic, assign, readonly) CFProgressHUDStyle style;

/** HUD在哪个view上展示 */
@property (nonatomic, weak, readonly, nullable) UIView *targetView;

/** 代理 */
@property (nonatomic, weak, nullable) id <CFProgressHUDDelegate> delegate;

/** The actual HUD view visible on screen. You may add animations to this view. */
@property (nonatomic, strong, readonly, nonnull) UIView *HUDView;

/** HUD真正的内容视图,可以在该视图中添加额外的视图 */
@property (nonatomic, strong, readonly, nonnull) UIView *contentView;

/** 标题label */
@property (nonatomic, strong, readonly, nonnull) UILabel *textLabel;

/** 详情label */
@property (nonatomic, strong, readonly, nonnull) UILabel *detailTextLabel;

/** HUD指示view */
@property (nonatomic, strong, nullable) CFProgressHUDIndicatorView *indicatorView;

/** HUD阴影层，可选属性 */
@property (nonatomic, strong, nullable) CFProgressHUDShadow *shadow;

/** HUD内部控件的位置，默认是CFProgressHUDPositionCenter */
@property (nonatomic, assign) CFProgressHUDPosition position;

/** 动画设置，默认是CFProgressHUDFadeAnimation */
@property (nonatomic, strong, nonnull) CFProgressHUDAnimation *animation;

/**
 Interaction type of the HUD. Determines whether touches should be let through to the views behind the HUD.
 @sa JGProgressHUDInteractionType.
 @b Default: JGProgressHUDInteractionTypeBlockAllTouches.
 */
@property (nonatomic, assign) CFProgressHUDInteractionType interactionType;

/**
 Parallax mode for the HUD. This setting determines whether the HUD should have a parallax (@c UIDeviceMotion) effect.
 @sa JGProgressHUDParallaxMode.
 @b Default: JGProgressHUDParallaxModeDevice.
 */
@property (nonatomic, assign) CFProgressHUDParallaxMode parallaxMode;

/** 是否保持HUD宽高相等,默认为NO */
@property (nonatomic, assign) BOOL square;

/** 是否开始毛玻璃效果,默认为NO */
@property (nonatomic, assign) BOOL vibrancyEnabled;

/** cornerRadius,默认为10.0 */
@property (nonatomic, assign) CGFloat cornerRadius;

/**
 Insets the contents of the HUD.
 @b Default: (20, 20, 20, 20).
 */
@property (nonatomic, assign) UIEdgeInsets contentInsets;

/**
 Insets the HUD from the frame of the hosting view or from the specified frame to present the HUD from.
 @b Default: (20, 20, 20, 20).
 */
@property (nonatomic, assign) UIEdgeInsets marginInsets __attribute((deprecated(("Use layoutMargins instead."))));

/**
 @attention This property is deprecated and does nothing.
 */
@property (nonatomic, assign) NSTimeInterval layoutChangeAnimationDuration __attribute((deprecated(("Use UIView animation to animate layout changes. This allows setting a custom animation duration, animaiton curve and other options."))));

/**
 @return Whether the HUD is visible on screen.
 */
@property (nonatomic, assign, readonly, getter = isVisible) BOOL visible;

/**
 The progress to display using the @c progressIndicatorView. A change of this property is not animated. Use the @c setProgress:animated: method for an animated progress change.
 @b Default: 0.0.
 */
@property (nonatomic, assign) float progress;

/**
 Adjusts the current progress shown by the receiver, optionally animating the change.
 
 The current progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task. The default value is 0.0. Values less than 0.0 and greater than 1.0 are pinned to those limits.
 @param progress The new progress value.
 @param animated YES if the change should be animated, NO if the change should happen immediately.
 */
- (void)setProgress:(float)progress animated:(BOOL)animated;

/**
 Specifies a minimum time that the HUD will be on-screen. Useful to prevent the HUD from flashing quickly on the screen when indeterminate tasks complete more quickly than expected.
 @b Default: 0.0.
 */
@property (nonatomic, assign) NSTimeInterval minimumDisplayTime;

/**
 Determines whether Voice Over announcements should be made upon displaying the HUD (if Voice Over is active).
 @b Default: YES
 */
@property (nonatomic, assign) BOOL voiceOverEnabled;

#if TARGET_OS_IOS
/**
 A block to be invoked when the HUD view is tapped.
 @note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockTouchesOnHUDView or @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
 */
@property (nonatomic, copy, nullable) void (^tapOnHUDViewBlock)(CFProgressHUD *__nonnull HUD);

/**
 A block to be invoked when the area outside of the HUD view is tapped.
 @note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
 */
@property (nonatomic, copy, nullable) void (^tapOutsideBlock)(CFProgressHUD *__nonnull HUD);
#endif

- (void)showInView:(UIView *__nonnull)view;
- (void)showInView:(UIView *__nonnull)view animated:(BOOL)animated;

- (void)dismiss;
- (void)dismissAnimated:(BOOL)animated;
- (void)dismissAfterDelay:(NSTimeInterval)delay;
- (void)dismissAfterDelay:(NSTimeInterval)delay animated:(BOOL)animated;

@end

@interface CFProgressHUD (HUDManagement)

/**
 @param view The view to return all visible progress HUDs for.
 @return All visible progress HUDs in the view.
 */
+ (NSArray<CFProgressHUD *> *__nonnull)allProgressHUDsInView:(UIView *__nonnull)view;

/**
 @param view The view to return all visible progress HUDs for.
 @return All visible progress HUDs in the view and its subviews.
 */
+ (NSArray<CFProgressHUD *> *__nonnull)allProgressHUDsInViewHierarchy:(UIView *__nonnull)view;

@end

@protocol CFProgressHUDDelegate <NSObject>
@optional
- (void)progressHUD:(CFProgressHUD *__nonnull)progressHUD willPresentInView:(UIView *__nonnull)view;
- (void)progressHUD:(CFProgressHUD *__nonnull)progressHUD didPresentInView:(UIView *__nonnull)view;
- (void)progressHUD:(CFProgressHUD *__nonnull)progressHUD willDismissFromView:(UIView *__nonnull)view;
- (void)progressHUD:(CFProgressHUD *__nonnull)progressHUD didDismissFromView:(UIView *__nonnull)view;
@end
